<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org"
      xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head th:include="include :: header"></head>
<body class="hold-transition skin-blue sidebar-mini">

<section class="content-header">
    <h1>存档清单提交列表</h1>
</section>
<section class="content">
    <div class="row">
        <div class="col-xs-12">
            <div class="box">
                <div class="box-header">
                    <form id="queryForm" onsubmit="return false;">
                        <div class="row">
                            <div class="form-inline">
                                <div class="form-group">
                                    <label for="query-proCode">项目编码</label>
                                    <input id="query-proCode" type="text" name="proCode" class="form-control"
                                           placeholder="请输入项目编号">
                                </div>
                                <div class="form-group">
                                    <label for="query-proName">项目名称</label>
                                    <input id="query-proName" type="text" name="proName" class="form-control"
                                           placeholder="请输入项目名称">
                                </div>
                                <div class="form-group">
                                    <label for="query-malType">类型</label>
                                    <select id="query-malType" class="form-control" name="specialId">
                                        <option value="" selected>请选择</option>
                                        <option th:each="type : ${specials}" th:value="${type.id}"
                                                th:text="${type.name}"></option>
                                    </select>
                                </div>
                                <div class="form-group">
                                    <label for="query-part">部分</label>
                                    <input id="query-part" type="text" name="part" class="form-control"
                                           placeholder="请输入部分">
                                </div>
                                <div class="form-group">
                                    <label for="query-status">清单状态</label>
                                    <select id="query-status" class="form-control" name="status">
                                        <option value="">请选择</option>
                                        <option value="1" selected>未提交</option>
                                        <option value="2">待科级审</option>
                                        <option value="3">待部级审</option>
                                        <option value="4">待下发</option>
                                        <option value="5">待签收</option>
                                        <option value="6">已签收</option>
                                    </select>
                                </div>
                                <div class="form-group">
                                    <label for="query-startTime">提报日期</label>
                                    <input id="query-startTime" type="text" class="form-control datepicker" name="startTime"
                                           readonly="readonly"/>
                                    <label for="query-endTime"> 至 </label>
                                    <input id="query-endTime" type="text" class="form-control datepicker" name="endTime"
                                           readonly="readonly"/>
                                </div>
                                <button type="button" class="btn btn-success" id="btn-search"
                                        onclick="js.table.search(table)">
                                    <span class="Bold">搜索</span>
                                </button>
                            </div>
                        </div>
                    </form>
                </div>
                <div class="box-body">
                    <table id="bootstrap-table"></table>
                </div>
            </div>
        </div>
    </div>
</section>
<div th:include="include :: footer"></div>
<script th:inline="javascript">

    let table;

    /** 删除计划单 */
    function delSheet(id) {
        js.modal.confirm("删除计划单将同时删除计划明细，确认删除吗？", function () {
            js.post({
                url: ctx + "create/file/list/del",
                data: {id: id},
                success: function (result) {
                    if (result.type === web_status.SUCCESS) {
                        js.modal.success(result.msg);
                        js.table.refresh(table);
                    } else {
                        js.modal.warning(result.msg);
                    }
                }
            })
        })
    }

    /** 提交计划单 */
    function commitSheet(id) {
        js.modal.confirm("确认提交吗？", function () {
            js.post({
                url: ctx + "create/file/list/commit",
                data: {id: id},
                success: function (result) {
                    if (result.type === web_status.SUCCESS) {
                        js.modal.success(result.msg);
                        js.table.refresh(table);
                    } else {
                        js.modal.warning(result.msg);
                    }
                }
            })
        })
    }

    /** 计划单列表 */
    $(function () {
        table = js.table.init({
            url: ctx + "create/file/list/list",
            columns: [
                {
                    title: '序号', field: 'id', width: '50',
                    formatter: function (value, row, index) {
                        return index + 1;
                    }
                },
                {title: "项目编号", field: 'proCode'},
                {title: "项目名称", field: 'proName',width: '260px'},
                {title: "项目数量", field: 'proNum'},
                {title: "类型", field: 'special'},
                {title: "部分", field: 'part'},
                {title: "创建人", field: 'createNameOne'},
                {title: "清单状态", field: 'status',
                    formatter: function (value, row) {
                        if (value === 1 || value === 3) {
                            return '<span class="badge label-inverse">待提交</span>';
                        } else if (value === 2 && row.reviewCur === 1) {
                            return '<span class="badge label-warning">待科级审</span>';
                        } else if (value === 2 && row.verifyCur === 1) {
                            return '<span class="badge label-warning">待部级审</span>';
                        } else if(value ===5 && row.designStatus === 0) {
                            return '<span class="badge label-warning">待下发</span>';
                        } else if(value ===5 && row.designStatus ===1 && row.fileSignStatus === 0){
                            return '<span class="badge label-warning">待签收</span>';
                        } else if(value ===5 && row.designStatus ===1 && row.fileSignStatus === 1) {
                            return '<span class="badge label-success">已签收</span>';
                        } else {
                            return "无状态";
                        }
                    }
                },
                {title: "驳回原因", field: 'rejectReason',width: '100px'},
                {title: "提报日期", field: 'createTime'},
                {title: "批准日期", field: 'verifyTime'},
                {
                    title: "操作",
                    // width: '160px',
                    formatter: function (value, row) {
                        let actions = [];
                            actions.push('<a class="btn btn-info btn-xs" target="_blank" href="' + ctx + 'create/file/list/' + row.id + '" > 查看</a>');
                        if (hasP('file:submit:change') && row.mayChange === 1 ) {
                            actions.push('<a class="btn btn-warning btn-xs" href="' + ctx + 'create/file/list/change/' + row.id + '" > 变更</a>');
                        }
                        if (hasP('file:submit:edit') && (row.status === 1 || row.status === 3) && sessionUser.id === row.postUserId) {
                            actions.push('<a class="btn btn-warning btn-xs" href="' + ctx + 'create/file/list/edit/' + row.id + '" > 编辑</a>');
                            actions.push('<a class="btn btn-danger btn-xs" href="javascript:void(0)" onclick="delSheet(' + row.id + ')"> 删除</a>');
                        }
                        if (hasP('file:submit:commit') && (row.status === 1 || row.status === 3)) {
                            actions.push('<a class="btn btn-success btn-xs" href="javascript:void(0)" onclick="commitSheet(' + row.id + ')"> 提交</a>');
                        }
                        if(row.sheetId != null){
                            actions.push('<a class="btn btn-info btn-xs" target="_blank" onclick="historyList('+ row.id +')" > 查看历史版本</a>');
                        }
                        return actions.join('');
                    }
                }
            ]
        });

    });


    /** 跳转历史版本记录页面*/
    function historyList(id){
        // location.href = ctx + "create/file/list/history";
        debugger
        window.open(ctx + "create/file/list/history?sheetId="+id);
    }


</script>
</body>
</html>
